﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Resources;
using Microsoft.Phone.Info;

namespace Wp7Tools.Services {
    public class SystemService : ISystemService {
        public string GetResourceAsString(Uri resourceUri) {
            StreamResourceInfo resource = Application.GetResourceStream(resourceUri);
            using (StreamReader streamReader = new StreamReader(resource.Stream)) {
                return streamReader.ReadToEnd();
            }
        }

        public DateTime GetNow() {
            return DateTime.Now;
        }

		public bool IsLowMemoryDevice() {
			try {
				Int64 result = (Int64)DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit");
				return (result < 94371840L);
			}
			catch (ArgumentOutOfRangeException) {
				// Update not installed -> old device (512MB)
				return false;
			}
		}
    }
}